import gradio as gr
import cartpole as cartpole

env = cartpole.CartPoleEnv()
env.reset()
reward_counter = 0

def run(input):
    global reward_counter
    input = int(input)
    _, _, d, _ = env.step(input)
    if d:
        env.reset()
        reward_counter = 0
    else:
        reward_counter += 1
    return env.render(), str(reward_counter)

demo = gr.Interface(run, "text", ["image", "text"])

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", show_api=False)